package com.elaticsearch.doc;

import org.apache.http.HttpHost;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;

/**
 * @author:左泽林
 * @date:日期:2021-08-28-时间:15:55
 * @message:
 */
public class doc_get {
    public static void main(String[] args) throws IOException {
        //创建ES客户端
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("172.20.17.43",9200,"http"))
        );

        try {
            //查询数据
            GetRequest getRequest = new GetRequest();

            getRequest.index("user").id("1001"); //指定修改的id


            GetResponse response = esClient.get(getRequest, RequestOptions.DEFAULT);

            System.out.println("===============操作结果==============");
            System.out.println(response.getSourceAsString());
            System.out.println("===============操作结果==============");
        }catch (Exception e){
            System.out.println(e);
        }finally {
            esClient.close();
        }
    }
}
